﻿Imports System.IO
Public Class autologin
    Dim debugC = 0
    Dim USERNAME As String
    Dim PASSWORD As String
    Dim x As Integer

    Private Sub autologin_Load(sender As Object, e As EventArgs)
        x = 0
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        x = x + 1

        If x Mod 60 = 0 Then
            WebBrowser1.Navigate("http://www.wright.edu")
        End If


    End Sub
    Public Sub Webdonenav()
        If WebBrowser1.DocumentTitle = "User Identification Portal" Then
            enterinfo()

        Else
            MsgBox("No need to execute")
            Exit Sub
        End If
    End Sub
    Public Sub enterinfo()
        WebBrowser1.Document.GetElementById("user").SetAttribute("value", userBox.Text)
        WebBrowser1.Document.GetElementById("passwd").SetAttribute("value", passBox.Text)
        WebBrowser1.Document.GetElementById("submit").InvokeMember("click")


    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Label1.Text = Timer1.Interval

    End Sub
    
    Private Sub Form1_FormClosing(ByVal sender As Object, _
                              ByVal e As System.Windows.Forms.FormClosingEventArgs)
        If e.CloseReason = CloseReason.UserClosing Then
            'The user has requested the form be closed so hide instead instead.
            e.Cancel = True
            Me.Visible = False

        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs)
        startLogin()

    End Sub

    Private Sub debugOn() Handles Me.Click
        debugC = debugC + 1
        If debugTimer.Enabled = True Then
        Else
            debugTimer.Enabled = True
            debugTimer.Start()
        End If
        If debugC = 5 Then
            WebBrowser1.Show()
            Label1.Show()
        End If
    End Sub

    Public Sub startLogin()
        If userBox.Text = "" Then
            If USERNAME = "" Then
                Me.Show()
                MsgBox("You must enter a username and password.")
                Exit Sub
            End If
        Else

        End If
        If passBox.Text = "" Then
            If PASSWORD = "" Then
                Me.Show()
                MsgBox("You must enter a username and password.")
                Exit Sub

            End If
        Else

        End If

        WebBrowser1.Navigate("http://www.wright.edu")
    End Sub
    Private Sub debugTimer_Tick(sender As Object, e As EventArgs) Handles debugTimer.Tick

    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Webdonenav()
    End Sub

    Private Sub enterB_Click(sender As Object, e As EventArgs) Handles enterB.Click
        startLogin()
        Timer1.Enabled = True
        Timer1.Start()
        enterB.Hide()
    End Sub

    Private Sub userBox_TextChanged(sender As Object, e As EventArgs) Handles userBox.TextChanged
        enterB.Show()
    End Sub

    Private Sub passBox_TextChanged(sender As Object, e As EventArgs) Handles passBox.TextChanged
        enterB.Show()
    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        startLogin()
    End Sub

    Private Sub isRunningTimer_Tick(sender As Object, e As EventArgs) Handles isRunningTimer.Tick
        If Timer1.Enabled = True Then
            Label7.Text = "RUNNING"
            Label7.ForeColor = Color.Green
        Else
            Label7.Text = "NOT RUNNING"
            Label7.ForeColor = Color.Red

        End If
    End Sub

    Private Sub autologin_Load_1(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class